package com.sunmouse.toolkit.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sunmouse.toollib.adapter.BasicAdapter;
import com.sunmouse.toolkit.R;

import java.util.List;

/**
 * Created by leiyun on 2018/4/13.
 */
public class ItemAdapter extends BasicAdapter<ItemAdapter.ViewHolder, String> {

    private OnViewChangedListener mListener;

    public void setOnViewChangedListener(OnViewChangedListener mListener) {
        this.mListener = mListener;
    }

    public ItemAdapter(List<String> list, Context context) {
        super(list, context);
    }

    @Override
    protected View bindView(LayoutInflater inflater, ViewGroup parent, Context context, List<String> list, int position) {
        return inflater.inflate(R.layout.adapter_item, parent, false);
    }

    @Override
    protected ViewHolder bindViewHolder(View cv, ViewGroup parent, Context context) {
        return new ViewHolder(cv);
    }

    @Override
    protected void bindData(ViewHolder vh, int position, List<String> list, Context context) {
        vh.nameTv.setText(list.get(position));
        if (mListener!=null)mListener.onViewChanged(position);
//        LogUtils.v("----getPosition=" + position);
    }

    static class ViewHolder extends BasicAdapter.ViewHolder {
        TextView nameTv;

        public ViewHolder(View v) {
            super(v);
            this.nameTv = (TextView) v.findViewById(R.id.name_tv);
        }
    }

    public interface OnViewChangedListener {
        void onViewChanged(int position);
    }
}
